package com.weetop.cfw.message.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.ActivityUtils
import com.weetop.cfw.R
import com.weetop.cfw.base.presenter.imp.MessageDetailPresenterImp
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.base.view.MessageDetailView
import com.weetop.cfw.bean.MessageDetailBean
import kotlinx.android.synthetic.main.activity_message_detail.*

/**
 * 消息详情界面
 */
class MessageDetailActivity : CommonBaseActivity(),View.OnClickListener,MessageDetailView {

    private lateinit var messageDetailPresenterImp: MessageDetailPresenterImp

    companion object{
        private const val MESSAGE_ID = "MESSAGE_ID"
        fun startMessageDetailActivity(context: Context,messageId:Int){
            val intent = Intent(context,MessageDetailActivity::class.java)
            intent.putExtra(MESSAGE_ID,messageId)
            ActivityUtils.startActivity(intent)
        }
    }

    override fun onClick(p0: View?) {
        when(p0?.id){
            R.id.imageMessageDetailBack -> ActivityUtils.finishActivity(this)
        }
    }

    override fun getLayoutId() = R.layout.activity_message_detail

    override fun initView(savedInstanceState: Bundle?) {
       setViewsOnClickListener(this,imageMessageDetailBack)
    }

    override fun initData(savedInstanceState: Bundle?) {
        messageDetailPresenterImp = MessageDetailPresenterImp()
        messageDetailPresenterImp.attachView(this)

        val id = intent!!.getIntExtra(MESSAGE_ID,0)
        messageDetailPresenterImp.getMessageDetailData(this,id)
    }

    override fun onDestroy() {
        super.onDestroy()
        messageDetailPresenterImp.detachView()
    }

    /**
     * 消息详情获取成功
     */
    override fun getMessageDetailDataSuccess(messageDetailBean: MessageDetailBean?) {
        if(messageDetailBean != null){
            textMessageUpdateTime.text = messageDetailBean.msgdate
            textMessageTitle.text = messageDetailBean.title
            textMessageContent.text = messageDetailBean.content
        }
    }

}
